package net.dfrz.oa.pojo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * 一级菜单类
 * @author vovh
 *
 */
@Entity
@Table(name="t_onecategory")
public class OneCategory implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;//菜单名称
	private Autority autority;// 1-1 autorityId
	private Set<TwoCategory> twoCategories = new HashSet<TwoCategory>();//n-1
	@GeneratedValue
	@Column(name="id")
	@Id
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@JoinColumn(name="autorityId",unique=true)
	@OneToOne
	public Autority getAutority() {
		return autority;
	}
	public void setAutority(Autority autority) {
		this.autority = autority;
	}

	//映射单向 1-n 的关联关系
	//使用 @OneToMany 来映射 1-n 的关联关系
	//使用 @JoinColumn 来映射外键列的名称
	//可以使用 @OneToMany 的 fetch 属性来修改默认的加载策略
	//可以通过 @OneToMany 的 cascade 属性来修改默认的删除策略. 
	//注意: 若在 1 的一端的 @OneToMany 中使用 mappedBy 属性, 则 @OneToMany 端就不能再使用 @JoinColumn 属性了. 
	@OneToMany(fetch=FetchType.EAGER,mappedBy="oneCategory")
	public Set<TwoCategory> getTwoCategories() {
		return twoCategories;
	}
	public void setTwoCategories(Set<TwoCategory> twoCategories) {
		this.twoCategories = twoCategories;
	}
	
}
